<?php
namespace app\admin\logic;

use think\Model;
use app\admin\model\MenuModel;

class MenuLogic extends Model
{
	// 生成后台菜单
	public function get_menu_arr()
	{

		$where = ['show' => 1];
		$order = "ordernum asc";
		// 查询所有菜单
		$menu  = new MenuModel();
		$res   = $menu->get_list($where, $order);
		
		// 生成菜单树
		$arr   = get_menu_tree($res);

        return $arr;
	}
	

	// 父级菜单数组
	public function get_parent_arr()
	{
		$where = "pid = 1";
		$order = "nav_id asc";
		// 查询所有菜单
		$menu  = new MenuModel();
		$res   = $menu->get_list($where, $order);

		if (!empty($res)) {
			$list = [];
			foreach ($res as $k => $v) {
				$list[$v['nav_id']] = $v['name'];
			}
		}

		return $list;
	}

	// 一级菜单
	public function get_parent_list()
	{
		$where = "pid <= 1";
		$order = "nav_id asc";
		$field = "nav_id, pid, name";
		// 查询所有菜单
		$menu  = new MenuModel();
		$res   = $menu->get_list($where, $order, $field);

		return $res;
	}


}